﻿#ifndef HELLO_ACTIVATOR_H
#define HELLO_ACTIVATOR_H

#include <ctkPluginActivator.h>
#include <ctkPluginContext.h>
#include "hello_service.h"
#include "service_factory.h"

class HelloActivator : public QObject, public ctkPluginActivator
{
    Q_OBJECT
    Q_INTERFACES(ctkPluginActivator)
    Q_PLUGIN_METADATA(IID "HELLO")

public:
    // 注册服务工厂
    void start(ctkPluginContext* context) {
        // 当你在 HelloActivator 中注册服务工厂时，任何插件（包括 system.plugin）都可以请求该服务。
        ServiceFactory *factory = new ServiceFactory();
        context->registerService<HelloService>(factory);

        //// 调用 HelloService 接口
        //ctkServiceReference helloServiceRef = context->getServiceReference<HelloService>();
        //if (helloServiceRef) {
        //    HelloService* helloService = qobject_cast<HelloService*>(context->getService(helloServiceRef));
        //    if (helloService != nullptr) {
        //        helloService->sayHello();
        //        qDebug() << "HelloService called from HelloActivator";
        //    }
        //}
    }

    void stop(ctkPluginContext* context) {
        Q_UNUSED(context)
    }
};

#endif // HELLO_ACTIVATOR_H
